import { defineStore } from "pinia";
import axios from "axios";
import { ref } from "vue";

const useCinemaStore = defineStore('cinemaStore', () => {
    // setupStore和optionStore没有谁好谁坏，只是语法上的区别罢了，一个更接近VOA，一个更接近VCA
    const cinemaList = ref([]);

    const getCinemaList = async () => {
        let res = await axios({
            method: 'get',
            url: 'https://m.maizuo.com/gateway?cityId=440300&ticketFlag=1&k=1866886',
            headers: {
                'X-Client-Info': '{"a":"3000","ch":"1002","v":"5.2.1","e":"16926962702329006145798145"}',
                'X-Host': 'mall.film-ticket.cinema.list'
            }
        });
        cinemaList.value = res.data.data.cinemas;
    }

    const filterCinemaList = (eTicketFlag) => {
        return cinemaList.value.filter(cinema => cinema.eTicketFlag == eTicketFlag)
    }

    return {
        cinemaList,
        getCinemaList,
        filterCinemaList
    }
});

export default useCinemaStore;